RSpec "undefined local variable or method `user'"

Posted by Justin on Stack Overflow See other posts from Stack Overflow or by Justin
Published on 2012-06-03T03:46:00Z Indexed on 2012/06/03 4:40 UTC
Read the original article Hit count: 128

I have the following test written in RSpec:

describe '#create' do
  ...
  it 'redirects users to profile page' do
    response.should redirect_to user_path(user)
  end
  ...
...

And the following in my UsersController:

def create
  @user = User.new(params[:user])
  if @user.save
    redirect_to user_path(@user)
  end
end

Does anyone know why this is returning the following error:

NameError: undefined local variable or method 'user'

I also tried changing this to be root_url in both cases instead of user_path(user) and it gave a different error saying:

Expected response to be a <:redirect>, but was <200>

Does anyone know what the issue might be? I have double-checked my code and have seen similar questions posted online, but haven't been able to find a solution. Thanks in advance for any help!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3